<template>
	<view class="page">
		<navbar backIconName="arrow-left" title="任务码" :titleStyle="titleStyle"></navbar>
		<scroll-view class="scroll-view_H" scroll-y="true">
			<view :style="{height:statusHeight+'px'}"></view>

			<view class="inCompany-task">
				<view class="task-item normal">
					<view class="left">
						<view class="top">
							<text
								style="font-size: 30rpx;color: #666;flex: 1;">{{type == '1'?taskObj.enterpriseTaskNo:(type == '2' || type == '3')?'':''}}</text>
							<!-- <text
								class="status">{{taskObj.status == '0'?'待入企':taskObj.status == '1'?'已入企':taskObj.status == '2'?'待企业评价':taskObj.status == '3'?'已评价':''}}</text> -->
							<text class="status"
								:style="{background:fontColor}">{{type == '1'?'计划入企':(type == '2' || type == '3')?'临时入企':''}}</text>
						</view>
						<text
							style="font-size: 28rpx;color: #666;margin: 20rpx 0rpx;font-weight: bold;">{{taskObj.taskName || '-'}}</text>
						<text
							style="font-size: 26rpx;color: #666;margin-bottom: 14rpx;">入企类型：{{taskObj.taskTypeName}}</text>
						<text
							style="font-size: 26rpx;color: #666;margin-bottom: 14rpx;">入企日期：{{taskObj.enterprisePlanDate}}</text>
					</view>
				</view>
			</view>
			<view class="inCompany-task" style="padding-top: 0px;">
				<view class="task-item" style="padding: 24px;">
					<QiyanQrcode ref="myQrCode" :text="qrCodeUrl" :logo="logoImage" :logoSize="70" :size="qrCodeWidth"
						:foreground="fontColor" id="qrcode1"></QiyanQrcode>
				</view>
			</view>

			<view class="menu-button">
				<view class="but" style="flex: 1;border: 1px solid #3c9cff;">
					<text :style="{color:'#3c9cff'}" @click="back">返回</text>
				</view>
				<view class="but" style="flex: 3;margin-left: 20px;background-color: #3c9cff;border: 1px solid #3c9cff;" @click="submitInCompany">
					<text :style="{color:'#fff'}">确认入企</text>
				</view>
			</view>


		</scroll-view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		getTaskList,
		sureEnter,
		mobileCreateTask,
	} from '@/api/pagesMall'
	import {
		decrypt,
		encrypt,
	} from '@/utils/sm4.js'
	import {
		showConfirm,
	} from "@/utils/common.js"
	import store from '@/store'
	import QiyanQrcode from "@/components/qiyan-qrcode/qiyan-qrcode.vue"
	let App = getApp();
	export default {
		components: {
			QiyanQrcode,
		},
		data() {
			return {
				logoImage: require('@/static/wx-ico.jpg'),
				qrCodeUrl: '',
				qrCodeWidth: App.globalData.screenWidth - 92,
				statusHeight: 44 + App.globalData.statusBarHeight,
				titleStyle: {
					color: "#ffffff",
					fontWeight: "bold",
					fontSize: "18px"
				},
				defaultTask: 0,
				taskList: [],
				socialCreditNumber: "",
				userId: store.state.user.USER_OPENID,
				userInfo: store.state.user.USER_INFO,
				companyInfo: {
					companyName: '',
					socialCreditNumber: '',
				},
				taskObj: null,
				fontColor: "#67c23a",
				type: "",
			};
		},
		onLoad(options) {
			this.type = options.type
			if (options.type == '1' || options.type == '3') {
				this.fontColor = "#67c23a"
			}
			if (options.type == '2') {
				this.fontColor = "#e6a23c"
			}
			this.taskObj = JSON.parse(options.creatTaskInfo)
			if (this.taskObj.enterpriseTaskNo != '') {
				this.qrCodeUrl = "?enterpriseTaskNo=" + this.taskObj.enterpriseTaskNo + '&view=1'
			} else {
				this.qrCodeUrl = "?enterpriseTaskNo=" + this.taskObj.socialCreditNumber + '&view=2'
				uni.setStorageSync('taskInfo', JSON.stringify(this.taskObj))
			}
		},
		methods: {
			/* 返回上一页 */
			back() {
				uni.navigateBack()
			},
			/* 确认入企 */
			submitInCompany() {
				if (this.type == '1') {
					showConfirm('确认要提交入企？').then(res => {
						if (res.confirm) {
							sureEnter({
								enterpriseTaskNo: this.taskObj.enterpriseTaskNo,
								userId: this.userId
							}).then(res => {
								uni.$u.toast('入企成功！')
								setTimeout(() => {
									uni.navigateTo({
										url: '/pages-mine/pages/enterCpRecord/detail?enterpriseTaskNo=' +
											this.taskObj.enterpriseTaskNo + '&delta=1'
									});
								}, 1000)
							});
						}
					});
				}
				if (this.type == '2' || this.type == '3') {
					showConfirm('确认要提临时入企任务？').then(res => {
						if (res.confirm) {
							mobileCreateTask(this.taskObj).then(res => {
								if (res.code == 200) {
									uni.$u.toast('临时入企任务创建成功！')
									setTimeout(() => {
										uni.navigateTo({
											url: '/pages-mine/pages/enterCpRecord/detail?enterpriseTaskNo=' +
												res.data.enterpriseTaskNo + '&delta=2'
										});
									}, 1000)
								}
							});
						}
					});
				}
			},

		}
	};
</script>

<style lang="scss" scoped>
	.page {
		position: relative;
	}

	.menu-button {
		display: flex;
		align-items: center;
		padding: 20px;

		.but {
			background-color: #fff;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 12rpx;
			box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.15);
			font-size: 32rpx;
			font-weight: bold;
			padding: 24rpx 24rpx;
		}
	}

	.submit-content {
		padding: 30rpx;
		height: 200rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
	}

	.scroll-view_H {
		width: 100%;
		height: 100%;

		.inCompany-task {
			display: flex;
			flex-direction: column;
			padding: 20px;

			.task-item {
				display: flex;
				align-items: center;
				justify-content: center;
				padding: 12px;
				background-color: #fff;
				border-radius: 12rpx;
				box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.15);

				.left {
					flex: 1;
					display: flex;
					flex-direction: column;

					.top {
						display: flex;
						align-items: center;
						padding-bottom: 20rpx;
						border-bottom: 1px solid #D8D8D8;

						.status {
							font-size: 24rpx;
							color: #323232;
							font-weight: bold;
							color: #fff;
							padding: 4rpx 10rpx;
							border-radius: 10rpx;
						}
					}
				}
			}
		}


	}
</style>